<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <%@ include file="/WEB-INF/views/include/head.jsp"%> 
        <link rel="stylesheet" href="css/layerSm.css">
        <script type="text/javascript">
            $(document).ready(function(){
                $("#styleCategoryCd,#fitCd,#sizegroupCd,#sizeCd").select2();
                var form = $("#inputForm");
                form.validate();//验证指定的表单
                $("#savebtn").click(function(){
                    if (form.valid()) {//如果表单验证成功，则进行提交。
                        save();
                        return false;
                    }
                })
            });

            /* 保存编辑信息 */
            function save(){
            	$('.showHtml').find('input,select').attr('disabled',false);
            	$('#styleCategoryCd').attr('disabled',false); 
            	$('#sizegroupCd').attr('disabled',false); 
            	$('#fitCd').attr('disabled',false); 
            	$("#parentTbody").find("tr.none").remove();
            	setIndex();

            	var params = $("#inputForm").serialize();
                var sizeUnitCost =$('#sizeUnitCost').val();
                if(/^[1-9]\d{0,6}(?:\.\d{1,3})?$/.test(sizeUnitCost)){
                    $.post("${ctx}/fabric/consumption/save",params,function(result){
                     /!* 弹出提示框,刷新父页面,关闭当前页面 *!/
                     tipParent(result.message);
                     window.parent.frames[0].searchListForm();
                     closeWin();
                     },'json');
                }else{
                    // 请输入合法单耗！
                    layer.msg('<spring:message code="please_unitcost_not_exist_alert"/>', {time:1000});
                    return;
                }
            }

            // 重新加载子项
            function reloadSubItem() {
                $.post("${ctx}/custom/customitem/searchSubList?itemValue = " + $('#itemValue').val(), "", function(result) {
                    var h = $(callBackHtml(result)).find("#subItem").html();
                    $('#subItem').html(h);
                    // 添加样式
                    $('#subItemsList').addClass("tabScroll");
                    var theadW = $('.tabScroll thead').width()
                    var theadTh = $('.tabScroll thead tr th').length
                    $('.tabScroll thead tr th').width(theadW/theadTh)
                    $('.tabScroll tbody tr:first-child td').each(function(){
                        var indexNum = $(this).index()
                        var tdWidth = $('.tabScroll tbody tr:first-child td').eq(indexNum).css('width')
                        $('.tabScroll thead tr th').eq(indexNum).width(tdWidth);
                    })
                }, 'html');

            }
            //尺码组联动
            function subStyleSize(t,id){
                var code=$(t).find("option:selected").attr("data-value");
                var param={"code":code};
                $.post("${ctx}/fabric/consumption/styleSize",param,function(result){
                    var html="<option value=''><spring:message code='size_pleaseChoosed'/></option>";
                    $.each(result,function(i,e){
                        html+="<option value='"+e.itemCode+"-"+e.itemValue+"'>"+e.itemName+"</option>";
                    });
                    $("#"+id).html(html);
                    $("#"+id).select2();
                },'json');
            }
            
            function addShelvesCheck(obj){                
            	/* 获取当前行的值 */            	
                var tr = obj.parentNode.parentNode;
            	/*var index = tr.rowIndex;*/
                var consumptionCD = $(tr).find('input')[0].value;
                var consumptionValue = $(tr).find('input')[1].value;                           	
                var sizeUnitCost = $(tr).find('input')[2].value;
            	popup('900px','484px','${ctx}/fabric/consumption/add?consumptionCD='+consumptionCD+'&sizeUnitCost='+sizeUnitCost+'&consumptionValue'+consumptionValue);
            	
                }
            
            /* 删除  */    	 
       	 function deleteCurrentRow(obj){
       		 if (confirm("<spring:message code="warehouse_shelves_areYouSure"/>")) {
                  var tr=obj.parentNode.parentNode;  
                  var tbody=tr.parentNode;  
                  tbody.removeChild(tr);         			
       		}
       	 }
            
       	function addRow(itemCd,itemValue,itemNameCn,sizeUnitCost,consumptionCn){
       		var tempDataCells = "";
       		var hiddenHtml = "";
       		var tbodyTemp = $("#parentTbody");
       		var trHtml = $("#hiddenTr.none").clone();
       		tempDataCells=$(trHtml)[0].cells;
       		tempDataCells[1].innerHTML = consumptionCn;
       		tempDataCells[2].innerHTML = itemNameCn;
       		tempDataCells[3].innerHTML = sizeUnitCost;
       		hiddenHtml += "<input type='hidden' name='consumptionList[tempIndex].consumptionCD' value='"+itemCd+"'>";
       		hiddenHtml += "<input type='hidden' name='consumptionList[tempIndex].consumptionValue' value='"+itemValue+"'>";
       		hiddenHtml += "<input type='hidden' name='consumptionList[tempIndex].sizeUnitCost' value='"+sizeUnitCost+"'>";
       		tempDataCells[4].innerHTML = hiddenHtml;
       		$(trHtml)[0].className="";
       		trHtml.appendTo(tbodyTemp);
       	}
       	/* 设置下标  */
        function setIndex(){
       		var tempIndex;
            var reg=/tempIndex/g;
    		var trPr = $("#parentTbody tr").length;
    		if (trPr >= 1) {
    			for (var i = 0; i < trPr; i++) {
                        var tableFit = $("#parentTbody tr").eq(i);
    					$(tableFit).html($(tableFit).html().replace(reg,i));
    			}
    		}
    	}   
           
        </script>
    </head>
<body>
<form id="inputForm" method="post" style="width: 800px;">
<!-- 编辑头部 -->     
        <div id="createHead" class="layerHeader clearfix" style="width: 800px;">
        <p class="headerTitle">
            <!-- 编辑定制项目--><!-- 新建定制项目-->
            <c:choose>
                <c:when test="${not empty consumption.sizeUnitCostId}"><spring:message code="size_editSizeCost"/></c:when>
                <c:otherwise><spring:message code="size_createSizeCost"/></c:otherwise>
            </c:choose>
        </p>
        <div class="headerButton clearfix">
            <c:choose>
                <c:when test="${not empty consumption.sizeUnitCostId}">
                    <button type="button" id="savebtn" onclick="save()"><spring:message code="common_save" /></button>
                </c:when>
                <c:otherwise><button type="button" id="savebtn" onclick="" ><spring:message code="common_save" /></button></c:otherwise>
            </c:choose>
          <!-- 取消 -->
          <button type="button" onclick="closeWin()"><spring:message code="purchaseAdvance_edit_cancle"/></button>
    </div>   
</div>               
        <c:set value="<%=ResourcesUtil.getConfig(\"size_styleCategory\")%>" var="styleCategory" />
        <c:set value="<%=ResourcesUtil.getConfig(\"size_styleFitCd\")%>" var="styleFit" />
        <c:set value="<%=ResourcesUtil.getConfig(\"size_styleSizeGroupCd\")%>" var="sizeGroup" />
        <input type="hidden" id="sizeUnitCostId" name="sizeUnitCostId" value="${consumption.sizeUnitCostId}"/>
        <input type="hidden"  name="version" value="${consumption.version}"/>
       <div class="" style="width: 800px;height: 600px">
           <div class="tabSm smOrderBox" style="width: 800px;height: 500px">
               <div class="tableBox">
                   <div class="col-50 items clearfix haveToBox">
                       <!-- 款式类别 -->
                       <p class="tit"><spring:message code="size_styleCategory"/></p>
                       <c:choose>
                           <c:when test="${consumption.sizeUnitCostId!=null&&consumption.sizeUnitCostId!=''}">
                               <p >${fns:getDictName(consumption.styleCategoryCd)}</p>
                               <input type="hidden"  name="styleCategoryCd"  value="${consumption.styleCategoryCd}"/>
                           </c:when>
                           <c:otherwise>
                               <select style="width:125px" id="styleCategoryCd" name="styleCategoryCd" data-rule-required="true" data-msg-required="<spring:message code="custom_style_type_alert"/>" >
                                   <option value=""><spring:message code="myWarehouse_pleaseChoosed"/></option>
                                   <c:forEach items="${fns:getDictList(styleCategory)}"   var="category">
                                       <option  <c:if test="${fn:split(consumption.styleCategoryCd,'-')[1] eq category.itemValue}">selected="selected"</c:if> value="${category.itemCode}-${category.itemValue}" >
                                               ${category.itemName}
                                       </option>
                                   </c:forEach>
                               </select>
                           </c:otherwise>
                       </c:choose>
                       <p class="haveTo">*</p>
                   </div>
                   <div class="col-50 items clearfix haveToBox">
                       <!-- 尺码组 -->
                       <p class="tit"><spring:message code="size_sizeGroup"/></p>
                       <c:choose>
                           <c:when test="${consumption.sizeUnitCostId!=null&&consumption.sizeUnitCostId!=''}">
                               <p class="rtname fl">${fns:getDictName(consumption.styleSizeGroupCd)} ${fns:getDictName(consumption.styleSizeCd)}</p>
                               <input type="hidden" id="styleSizeGroupCd" name="styleSizeGroupCd" value="${consumption.styleSizeGroupCd}"/>
                               <input type="hidden" id="styleSizeCd" name="styleSizeCd"  value="${consumption.styleSizeCd}"/>
                           </c:when>
                           <c:otherwise>
                               <select style="width:125px" id="styleSizeGroupCd" name="styleSizeGroupCd" onchange="subStyleSize(this,'styleSizeCd')" data-rule-required="true" data-msg-required="<spring:message code="custom_styleSizeGroupCd_alert"/>" >
                                   <option value=""><spring:message code="size_pleaseChoosed"/></option>
                                   <c:forEach items="${fns:getDictList(sizeGroup)}"   var="group">
                                       <option data-value="${group.itemValue}" <c:if test="${fn:split(consumption.styleSizeGroupCd,'-')[1] eq group.itemValue}">selected="selected"</c:if> value="${group.itemCode}-${group.itemValue}" >
                                               ${group.itemName}
                                       </option>
                                   </c:forEach>
                               </select>
                               <select style="width:100px"  id="styleSizeCd" name="styleSizeCd" data-rule-required="true" data-msg-required="<spring:message code="custom_styleSizeCd_alert"/>">
                                   <option value=""><spring:message code="size_pleaseChoosed"/></option>
                                   <c:forEach items="${fns:getDictList(fn:split('', '-')[1])}" var="styleSize">
                                       <option
                                               value="${styleSize.itemCode}-${styleSize.itemValue}">
                                               ${styleSize.itemName}
                                       </option>
                                   </c:forEach>
                               </select>
                           </c:otherwise>
                       </c:choose>
                       <p class="haveTo">*</p>
                   </div>
               </div>
                <div class="tableBox">
                    <div class="col-50 items clearfix haveToBox">
                        <!-- 版型 -->
                        <p class="tit"><spring:message code="size_styleFit"/></p>
                        <c:choose>
                                <c:when test="${consumption.sizeUnitCostId!=null&&consumption.sizeUnitCostId!=''}">
                                    <p class="">${fns:getDictName(consumption.fitCd)}</p>
                                     <input type="hidden" id="fitCd" name="fitCd"  data-rule-required="true"  value="${consumption.fitCd}"/>
                                 </c:when>
                                <c:otherwise>
                                     <select style="width:125px" id="fitCd" name="fitCd"  data-rule-required="true"  data-msg-required="<spring:message code="custom_fit_CD_alert" />">
                                 <option value=""><spring:message code="myWarehouse_pleaseChoosed"/></option>
                                  <c:forEach items="${fns:getDictList(styleFit)}"   var="fit">
                                     <option  <c:if test="${fn:split(consumption.fitCd,'-')[1] eq fit.itemValue}">selected="selected"</c:if> value="${fit.itemCode}-${fit.itemValue}" >
                                         ${fit.itemName}
                                     </option>
                                 </c:forEach>
                             </select>
                             </c:otherwise>
                        </c:choose>
                        <p class="haveTo">*</p>
                    </div>
                    <div class="col-50 items clearfix haveToBox ">
                        <!-- 状态  -->
        				        <p class="tit"><spring:message code="dict_state" /></p>
                                <c:choose>
                            <c:when test="${consumption.sizeUnitCostId!=null&&consumption.sizeUnitCostId!=''}">
                                <p class="">
                                    <c:choose>
                                        <c:when test="${consumption.enableFlag eq 1}"><spring:message code="size_enable"/></c:when>
                                    </c:choose>
                                    <c:choose>
                                        <c:when test="${consumption.enableFlag eq 0}"><spring:message code="size_disable"/></c:when>
                                    </c:choose>
                                </p>
                                <input type="hidden"  name="enableFlag" value="${consumption.enableFlag}"/>
                            </c:when>
                            <c:otherwise>
                            <div class="labelBox">
						<!--启用-->
						<label> <input type="radio" name="enableFlag"
							checked='checked' value="1"
							<c:if test="${consumption.enableFlag eq 1}">checked="checked"</c:if>
							class="rast" /> <spring:message code="dict_enable" />
						</label>
						<!--停用-->
						<label><input type="radio" name="enableFlag" value="0"
							<c:if test="${consumption.enableFlag eq 0}">checked="checked"</c:if>
							class="rast" /> <spring:message code="dict_disable" />
						</label>
						</div>
                            </c:otherwise>
                            </c:choose>
                    </div>
                </div>
                <div style="width: calc(100% - 75px);float: left;">
                    <div class="col-50 items clearfix haveToBox">
                        <!-- 单耗-->
                        <p class="tit"><spring:message code="size_Cost" /></p>
                        <input  id="sizeUnitCost" name="sizeUnitCost"
                                data-rule-required="true"  data-msg-required="<spring:message code="please_unitcost_alert" />"
                                value="${consumption.sizeUnitCost}">
                        <p class="haveTo">*</p>
                    </div>
                    <div class="col-50 items clearfix haveToBox">
                        <!-- 备注-->
                        <p class="tit"><spring:message code="size_remarks"/></p>
                            <!-- 请输入备注内容 -->
                            <textarea name="remarks" maxlength="200" style="width:200px">${consumption.remarks}</textarea>
                    </div>
                </div >
                </div>
       </div>
        </form>
    </body>
</html>